import os
import sqlite3

DB_PATH = os.path.join(os.path.dirname(__file__), '..', 'db')

class UserHandler(object):
    def __init__(self):
        self.db_file = os.path.join(DB_PATH, 'user.db')
        if os.path.isfile(self.db_file):	
            self.cx = sqlite3.connect(self.db_file)
            self.cu = self.cx.cursor()
        else:
            self.cx = sqlite3.connect(self.db_file)
            self.cu = self.cx.cursor()
            self.init_tables()
        
    def init_tables(self):
        print "init...."
        self.cu.execute('create table users (id integer primary key,'
                        'name varchar(255), title varchar(255), status varchar(10))')
        self.cu.execute('create table permission (id integer primary key, name varchar(80))')
